package com.xbongbong.sso.enums;

import lombok.Getter;

import java.util.Objects;

/**
 * 授权阶段类型
 */
@Getter
public enum StageTypeEnum {
    /**
     *
     */
    REQUEST(1,"REQUEST"),
    RESPONSE(2,"RESPONSE"),
    UNKNOWN(-1,"unknown"),
    ;

    private Integer code;

    private String name;

    StageTypeEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 根据code获取枚举
     * @return
     */
    public static StageTypeEnum getByCode(Integer code) {
        if (code == null) {
            return UNKNOWN;
        }
        for (StageTypeEnum cache : values()) {
            if (Objects.equals(cache.getCode(), code)) {
                return cache;
            }
        }
        return UNKNOWN;
    }
}
